package p_304

import IDoSome
import java.io.File
import java.net.ServerSocket
import java.util.concurrent.Executors
import java.util.logging.Level
import java.util.logging.Logger

/**
 * 服务端Socket 监听 8082 端口的请求
 */
class JHttp() : IDoSome {

    val rootDirec = File("D:\\web_project\\info_collector_mini\\sc_selfpay\\info_collector")
    val port = 8082

    companion object {
        private val logger = Logger.getLogger("JHttp")
        private const val MAX_TREADS = 50
        private const val INDEX_FILE = "index.html"
    }


    override fun doSome() {
        val pool = Executors.newFixedThreadPool(MAX_TREADS)
        try {
            val server = ServerSocket(port)
            while (true) {
                val socket = server.accept()
                val request = RequestProcessor(rootDirec, socket)
                pool.submit(request)
            }
        } catch (e: Exception) {
            e.printStackTrace()
            logger.log(Level.WARNING, e.message)
        }

    }


}